package com.erp.gather.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.erp.gather.domain.bo.ErpSellerCollectProductExpandBo;
import com.erp.gather.domain.vo.ErpSellerCollectProductExpandVo;
import com.erp.gather.service.IErpSellerCollectProductExpandService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 个人采集商品拓展
 *
 * @author erp
 * @date 2023-06-20
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/seller/sellerCollectProductExpand")
public class ErpSellerCollectProductExpandController extends BaseController {

    private final IErpSellerCollectProductExpandService iErpSellerCollectProductExpandService;

    /**
     * 查询个人采集商品拓展列表
     */
    @SaCheckPermission("seller:sellerCollectProductExpand:list")
    @GetMapping("/list")
    public TableDataInfo<ErpSellerCollectProductExpandVo> list(ErpSellerCollectProductExpandBo bo, PageQuery pageQuery) {
        return iErpSellerCollectProductExpandService.queryPageList(bo, pageQuery);
    }


    /**
     * 获取个人采集商品拓展详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("seller:sellerCollectProductExpand:query")
    @GetMapping("/{id}")
    public R<ErpSellerCollectProductExpandVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iErpSellerCollectProductExpandService.queryById(id));
    }

    /**
     * 新增个人采集商品拓展
     */
    @SaCheckPermission("seller:sellerCollectProductExpand:add")
    @Log(title = "个人采集商品拓展", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpSellerCollectProductExpandBo bo) {
        return toAjax(iErpSellerCollectProductExpandService.insertByBo(bo));
    }

    /**
     * 修改个人采集商品拓展
     */
    @SaCheckPermission("seller:sellerCollectProductExpand:edit")
    @Log(title = "个人采集商品拓展", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpSellerCollectProductExpandBo bo) {
        return toAjax(iErpSellerCollectProductExpandService.updateByBo(bo));
    }

    /**
     * 删除个人采集商品拓展
     *
     * @param ids 主键串
     */
    @SaCheckPermission("seller:sellerCollectProductExpand:remove")
    @Log(title = "个人采集商品拓展", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpSellerCollectProductExpandService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
